package com.security;

import lombok.Data;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @ClassName TokenInfo
 * @Description TODO 申请令牌，返回的字段
 * @Author wushaopei
 * @Date 2021/5/3 17:57
 * @Version 1.0
 */
@Data
public class TokenInfo {

    /**
     * @Description TODO
     */
    private String access_token;

    /**
     * 刷新令牌
     */
    private String refresh_token;

    /**
     * @Description TODO
     */
    private String token_type;

    /**
     * @Description TODO
     */
    private Long expires_in;

    /**
     * @Description TODO
     */
    private String scope;

    private LocalDateTime expireTime;

    // 初始化过期时间
    public TokenInfo init(){
      expireTime = LocalDateTime.now().plusSeconds(expires_in - 3);
      return this;
    }

    // 比较，过期时间是否在当前时间之前，如果是，就说明过期了
    public boolean isExpired() {
      return expireTime.isBefore(LocalDateTime.now());
    }
}
